package com.star.book.service.impl;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.google.common.collect.Maps;
import com.star.book.entity.BookInfo;
import com.star.book.mapper.BookInfoMapper;
import com.star.book.service.IBookInfoService;
import org.jsoup.Connection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Mr Kong
 * @since 2020-10-03
 */
@Service
public class BookInfoServiceImpl extends ServiceImpl<BookInfoMapper, BookInfo> implements IBookInfoService {

    @Autowired
    private IBookInfoService bookInfoService;

    @Override
    public int selectBookInfoCount() {
        return baseMapper.selectBookInfoCount();
    }

    @Override
    public List<BookInfo> findByPage(Integer id) {
        return baseMapper.findByPage(id);
    }

    @Override
    public Map<String, Object> bookInfo(Integer id) {
        Map<String, Object> bookInfoMap = Maps.newHashMap();
        List<BookInfo> list = bookInfoService.list();
        int bookInfoTotalCount = list.size();
        Integer page ;
        if(bookInfoTotalCount == 0 || bookInfoTotalCount < 0){
            page = 0;
        }else{
            page = bookInfoTotalCount / 10;
            if(bookInfoTotalCount % 10 > 0){
                page=page+1;
            }
        }
        bookInfoMap.put("page",page);
        List<BookInfo> byPage = baseMapper.findByPage(id);
        bookInfoMap.put("BookInfoByPage",byPage);
        return bookInfoMap;
    }
}
